/**
 *
 * options:{load:'', itemSelector:'.daily', 'pageSize': 10,s appendTo:'', callback: function(){}}
 * @default setting only for daily
 * @zli <studytime@163.com>
 **/
$.fn.contentLoader = function (options) {
	$options = $.extend({load:U('weibo/index/loadContent'), 
						 itemSelector:'.daily', 
						 pageSize: 0 , 
						 callback: function(){}
						}, 
						options);
	//var pageH = $(document.body).height(); 
	if (!$options.pageSize) $options.pageSize = $($options.itemSelector, element).length-1;
    var element = $(this).get(0);
    var loaded = []; // only load once
    var inLoading = 0; // only one in loading
    if (element) {
	    $(window).on('scroll.contentLoader', function () { 
		   /* var winH = $(window).height(); 
	        var scrollT = $(window).scrollTop()-$(element).offset().top; 
	        var _page = Math.ceil(scrollT/winH) + 1;*/
		   var _page = Math.ceil($($options.itemSelector, element).length/$options.pageSize)+1;
	       if ($.inArray(_page, loaded)==-1 && !inLoading) {
	       		inLoading = 1;
		    	//loading bar
		    	$obj = $('<div id="loading"><img src="/public/themes/aiyawa/images/loading-anim.gif" /></div>');
		    	$obj.appendTo(element);
		        $.get($options.load,{page:_page, size:$options.pageSize},function(data){ 
		        	loaded.push(_page++);
		            if(data){ 
		            	var _newList = $(data);
		                $obj.replaceWith(_newList);
		                if ($.isFunction($options.callback)) {
		                	$options.callback.call(_newList);
		                }
		                _page++;
		            }
		            inLoading = 0;
		            $('#loading', element).remove();
		        }); 
	        }
	    }); 	
    }	
}